package gui;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import logic.MainMidlet;
import logic.Point;

/**
 * template for screen with image and one button at the bottom
 * @author Rekin
 *
 */
public class ImageAndOkScreenTemplate extends Canvas{
	protected CanvasButton ok;
	protected Image im;
	
	/**
	 * default constructor
	 */
	public ImageAndOkScreenTemplate(){
		if(!Board.deviceBuild){
			ok = new CanvasButton(60, 25, new Point(getWidth()/2-30, getHeight()/2+50), "Ok");
		}
		else{
			ok = new CanvasButton(90, 45, new Point(getWidth()/2-45, getHeight()/2+50), "Ok");
		}
	}
	
	/**
	 * paintings
	 */
	protected void paint(Graphics g) {
		g.setColor(0,0,0);
		g.fillRect(0, 0, getWidth(), getHeight());	 //black background
		if(im!=null)
			g.drawImage(im, getWidth()/2-im.getWidth()/2, 10, Graphics.TOP | Graphics.LEFT);
		ok.paintMe(g);
	}
	
	/**
	 * handling button hit
	 * @param x horizontal coordinate of pointer pressed
	 * @param y vertical coordinate of pointer pressed
	 * @return true if button was hit or false otherwise
	 */
	private boolean buttonHit(int x, int y){
			int ex1=ok.getTopLeft().getX();
			int ex2=ex1 + ok.getMyWidth();
			int ey1=ok.getTopLeft().getY();
			int ey2=ey1 + ok.getMyHeight();
			
			if(x>=ex1 && x<=ex2 && y>=ey1 && y<=ey2){
				return true;
			}
		return false;
	}
	
	/**
	 * Canvas super class pointer pressing
	 */
	protected void pointerPressed(int x, int y){
		if(buttonHit(x, y)){
			MainMidlet.getMidletInstance().showMainMenu();
		}
	}
}
